package com.whub507.msgmanager.controller;

import com.whub507.msgmanager.common.Field;
import com.whub507.msgmanager.common.ResResult;
import com.whub507.msgmanager.domain.User;
import com.whub507.msgmanager.mapper.UserMapper;
import com.whub507.msgmanager.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@Api(tags = "用户相关接口")
@CrossOrigin
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserMapper userMapper;

    @Autowired
    private UserService userService;

    @GetMapping("/getApprove")
    @ApiOperation(value = "获取部门的审批负责人")
    public ResResult<List<User>> getApprove(String department){

        List<Field> fields = new ArrayList<>();
        fields.add(new Field("username","审批人姓名"));
        fields.add(new Field("phone","电话"));
        fields.add(new Field("department","部门"));
        fields.add(new Field("position","职务"));

        return ResResult.ok(userMapper.selectAllApproveByDepartment(department), fields, "返回该用户所有可选审批人");
    }

    @GetMapping("/getDepartment")
    @ApiOperation(value = "获取用户部门")
    public ResResult<String> getDepartmentById(Integer userId){
        return userService.getDepartmentById(userId);
    }

}
